package com.yyysj.friend.controller;

import com.yyysj.common.core.domain.Result;
import com.yyysj.common.core.domain.TableDataInfo;
import com.yyysj.friend.domain.dto.ExamQueryDTO;
import com.yyysj.friend.domain.dto.ExamRankDTO;
import com.yyysj.friend.domain.vo.ExamVO;
import com.yyysj.friend.service.IExamService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/exam")
public class ExamController {

    private final IExamService examService;

    @GetMapping("/semiLogin/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        List<ExamVO> examVOList =examService.list(examQueryDTO);
        if (examVOList == null || examVOList.size() <= 0) {
            return TableDataInfo.empty();
        }
        return TableDataInfo.success(examVOList, examVOList.size());
       // return examService.list(examQueryDTO);
    }

    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO) {
//        List<ExamVO> examVOList = examService.redisList(examQueryDTO);
//        if(examVOList == null || examVOList.size() <= 0) {
//            return TableDataInfo.empty();
//        }
//        return TableDataInfo.success(examVOList, examVOList.size());
        return examService.redisList(examQueryDTO);
    }

    @GetMapping("/rank/list")
    public TableDataInfo rankList(ExamRankDTO examRankDTO) {
        return examService.rankList(examRankDTO);
    }


    @GetMapping("/getFirstQuestion")
    public Result<String> getFirstQuestion(Long examId) {
        return Result.ok(examService.getFirstQuestion(examId));
    }

    @GetMapping("/preQuestion")
    public Result<String> preQuestion(Long examId, Long questionId) {
        return Result.ok(examService.preQuestion(examId, questionId));
    }

    @GetMapping("/nextQuestion")
    public Result<String> nextQuestion(Long examId, Long questionId) {
        return Result.ok(examService.nextQuestion(examId, questionId));
    }
}
